//简单TCP通信

package step2;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server extends Thread {

    @Override
    public void run() {
        try {
            //创建服务器端ServerSocket(ss)，指定端口号8000
            /********** Begin **********/
            ServerSocket ss = new ServerSocket(8000);

            /**********  end  **********/
            Socket s = ss.accept();
            DataOutputStream dos = new DataOutputStream(s.getOutputStream());
            DataInputStream dis = new DataInputStream(s.getInputStream());
            dos.writeUTF("你已经连上服务器了，告诉我你的姓名...");
            String name = dis.readUTF();
            dos.writeUTF("再见:" + name);
            s.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}